#include "Surface.h"

Surface g_pSurface;

void Surface::Init(PDWORD_PTR* pdwTable)
{
	static hook_t Hook( pdwTable );
	m_Surface = &Hook;
}

void Surface::DrawSetColor( int r, int g, int b, int a )
{
	typedef void ( __thiscall *tDrawSetColor )( void*, int, int, int, int );
	m_Surface->GetMethod< tDrawSetColor >( SURFACE_DRAWSETCOLOUR )( m_Surface->GetInstance(), r, g, b, a );
}

void Surface::DrawLine( int x0, int y0, int x1, int y1 )
{
	typedef void ( __thiscall *tDrawLine )( void*, int x0, int y0, int x1, int y1 );
	m_Surface->GetMethod< tDrawLine >( SURFACE_DRAWLINE )( m_Surface->GetInstance(), x0, y0, x1, y1 );
}

void Surface::DrawFilledRect( int x, int y, int w, int h )
{
	typedef void ( __thiscall *tDrawFilledRect )( void*, int x0, int y0, int x1, int y1 );
	m_Surface->GetMethod< tDrawFilledRect >( SURFACE_DRAWFILLEDRECT )( m_Surface->GetInstance(), x, y, x+w, y+h );
}

void Surface::DrawOutlinedRect( int x, int y, int w, int h )
{
	typedef void ( __thiscall *tDrawOutlinedRect )( void*, int x0, int y0, int x1, int y1 );
	m_Surface->GetMethod< tDrawOutlinedRect >( SURFACE_DRAWOUTLINEDRECT )( m_Surface->GetInstance(), x, y, x+w, y+h );
}

unsigned long Surface::CreateFont( )
{
	typedef unsigned long ( __thiscall *tCreateFont )( void* );
	return m_Surface->GetMethod< tCreateFont >( SURFACE_CREATEFONT )( m_Surface->GetInstance() );
}

bool Surface::SetFontGlyphSet( unsigned long font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags )
{
	typedef bool ( __thiscall *tSetFontGlyphSet )( void*, unsigned long font, const char *windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int nRangeMin, int nRangeMax );
	return m_Surface->GetMethod< tSetFontGlyphSet >( SURFACE_SETFONTGLYPHSET )( m_Surface->GetInstance(), font, windowsFontName, tall, weight, blur, scanlines, flags, 0, 0 );
}

void Surface::GetTextSize( unsigned long font, const wchar_t *text, int &wide, int &tall )
{
	typedef void ( __thiscall *tGetTextSize )( void*, unsigned long font, const wchar_t *text, int &wide, int &tall );
	m_Surface->GetMethod< tGetTextSize >( SURFACE_GETTEXTSIZE )( m_Surface->GetInstance(), font, text, wide, tall );
}

void Surface::DrawSetTextColour( int r, int g, int b, int a )
{
	typedef void ( __thiscall *tDrawSetTextColor )( void*, int r, int g, int b, int a );
	m_Surface->GetMethod< tDrawSetTextColor >( SURFACE_DRAWSETTEXTCOLOUR )( m_Surface->GetInstance(), r, g, b, a );
}

void Surface::DrawSetTextFont( unsigned long font )
{
	typedef void ( __thiscall *tDrawSetTextFont )( void*, unsigned long font );
	m_Surface->GetMethod< tDrawSetTextFont >( SURFACE_DRAWSETTEXTFONT )( m_Surface->GetInstance(), font );
}

void Surface::DrawSetTextPos( int x, int y )
{
	typedef void ( __thiscall *tDrawSetTextPos )( void*, int x, int y );
	m_Surface->GetMethod< tDrawSetTextPos >( SURFACE_DRAWSETTEXTPOS )( m_Surface->GetInstance(), x, y );
}

void Surface::DrawPrintText( const wchar_t *text, int textLen )
{
	typedef void ( __thiscall *tDrawPrintText )( void*, const wchar_t *text, int textLen, int drawType );
	m_Surface->GetMethod< tDrawPrintText >( SURFACE_DRAWPRINTTEXT )( m_Surface->GetInstance(), text, textLen, 0 );
}